﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Coding4Fun.Phone.Controls;

namespace Liuyi.Phone.LiveMSN
{
    public partial class MainPage : PhoneApplicationPage
    {
        /// <summary>
        /// MessagePrompt
        /// </summary>
        /// 我的字段 LIUYI-PC Liuyi 2012/1/9 创建
        private UserPrompt mp = new MessagePrompt();

        // Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="MainPage"/> class.
        /// </summary>
        /// 默认构造函数 LIUYI-PC Liuyi 2012/1/9 创建
        public MainPage()
        {
            InitializeComponent();
            //load
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        /// <summary>
        /// Handles the Loaded event of the MainPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            SystemTray.ProgressIndicator = Liuyi.get_ProgressIndicator("欢迎使用 LiveMessenger ！");
            //Home
            Liuyi.do_NavigateToHome(___WebBrowser_msn);
        }

        /// <summary>
        /// This method is called when the hardware Back button is pressed.
        /// </summary>
        /// <param name="e">Set e.Cancel to true to indicate that the request was handled by the application.</param>
        /// Inherited documentation LIUYI-PC Liuyi 2012/1/9 创建
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
            e.Cancel = true;
            if (mp.IsOpen)
            {
                mp.Hide();
            }
            else
            {
                mp = Liuyi.get_BackPrompt(___WebBrowser_msn);
                mp.Show();
            }
        }

        /// <summary>
        /// Handles the Navigating event of the ___WebBrowser_msn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.Phone.Controls.NavigatingEventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___WebBrowser_msn_Navigating(object sender, Microsoft.Phone.Controls.NavigatingEventArgs e)
        {
            // TODO: Add event handler implementation here.
        }

        /// <summary>
        /// Handles the Navigated event of the ___WebBrowser_msn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Navigation.NavigationEventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___WebBrowser_msn_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            // TODO: Add event handler implementation here.
            Liuyi.do_WebTitle(___WebBrowser_msn);
        }

        /// <summary>
        /// Handles the NavigationFailed event of the ___WebBrowser_msn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Navigation.NavigationFailedEventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___WebBrowser_msn_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            Liuyi.showException(e);
        }

        /// <summary>
        /// Handles the LoadCompleted event of the ___WebBrowser_msn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Navigation.NavigationEventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        void ___WebBrowser_msn_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            Liuyi.do_WebTitle(___WebBrowser_msn);
        }

        /// <summary>
        /// Handles the ScriptNotify event of the ___WebBrowser_msn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.Phone.Controls.NotifyEventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___WebBrowser_msn_ScriptNotify(object sender, Microsoft.Phone.Controls.NotifyEventArgs e)
        {
            // TODO: Add event handler implementation here.
            SystemTray.ProgressIndicator = Liuyi.get_ProgressIndicator(e.Value);
        }

        /// <summary>
        /// Handles the Click event of the ___ApplicationBarMenuItem_help control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___ApplicationBarMenuItem_help_Click(object sender, System.EventArgs e)
        {
            // TODO: Add event handler implementation here.
            mp = Liuyi.get_HelpPrompt();
            mp.Show();
        }

        /// <summary>
        /// Handles the Click event of the ___ApplicationBarMenuItem_about control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___ApplicationBarMenuItem_about_Click(object sender, System.EventArgs e)
        {
            // TODO: Add event handler implementation here.
            mp = Liuyi.get_AboutPrompt();
            mp.Show();
        }

        /// <summary>
        /// Handles the Click event of the ___ApplicationBarMenuItem_exit control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// Control event handler LIUYI-PC Liuyi 2012/1/9 创建
        private void ___ApplicationBarMenuItem_exit_Click(object sender, System.EventArgs e)
        {
            // TODO: Add event handler implementation here.
            mp = new MessagePrompt()
            {
                IsCancelVisible = true,
                Title = "退出提示",
                Message = "\n\t确认退出？\n",
            };
            mp.Show();
            mp.Completed += (a, b) =>
                {
                    if (b.PopUpResult == PopUpResult.Ok)
                    {
                        Liuyi.Exit();
                    }
                };
        }
    }
}